// 患者病历记录 -- 患者已保存的所有病历
import React, { Component } from 'react';
import { Card, Row, Col, Input, Select, Button, Table, message, Tree, Icon, Spin } from 'antd';
import { $http } from 'containers/config/https';
// import { handleExcel } from 'tools/handleExcel.js';
import store from 'store';
import Moment from 'moment';
import { dayFormat, Util } from 'tools/index';
import iconListvisits from 'assets/images/icon_listvisits.png';
import CommonPagination from 'components/pagination/index';
import RangeDatePicker from 'components/rangePicker/index';
import ColumnAuthoritysModel from 'pages/columnAuthority/ColumnAuthoritysModel';
import ElectronicCaseTemplate from 'pages/common/ElectronicCaseTemplate.jsx';

const { Option } = Select;
const { TreeNode } = Tree;

class PatientRecordsAll extends Component {
  constructor(props) {
    super(props);
    var userData = JSON.parse(sessionStorage.getItem('userData'));
    this.state = {
      userData,
      patientColumns: [],
      tableData: [],
      total: 0,
      page: 1,
      pageSize: 20,
      patientWidth: 0,
      basicHeight: 0,
      loading: false,
      detailTableData: [],
      detailPage: 1,
      detailPageSize: 20,
      detailTotal: 0,
      detailLoading: false,
      patMessage: undefined, // 人员标识
      medicalNo: undefined, // 住院号
      bedID: undefined, // 床号
      locID: userData && userData.locID ? userData.locID : undefined, // 科室名称
      selectedRowKeys: [],
      selectedRows: [],
      detailSelectedRowKeys: [],
      detailSelectedRows: [],
      locSelectData: [],
      bedData: [],
      medicalRecordTemplateSelectData: [],
      medicalRecordTemplateID: undefined,
      rowId: "",
      rowRow: {},
      admStatusCode: undefined, // 患者类型
      admStatusSelectData: [{
        id: "A",
        descripts: "在院",
        descriptsSPCode: "zy"
      }, {
        id: "D",
        descripts: "出院",
        descriptsSPCode: "cy"
      }],
      admTypeSelectData: [],
      admissionDate: undefined,
      dateFrom: undefined,
      dateTo: undefined,
      admSTDate: undefined,
      admSPDate: undefined,
      locType: "O^I^E^W^OI^OP",
      admStatusAble: false,
      bedIDAble: false,
      medicalNoAble: false,
      isSubmit: false,
      locDocData: [],
      admDocID: undefined, // 主管医生
      docNameAble: false,
      autoExpandParent: true,
      expandedKeys: [],
      selectedKeys: [],
      treeData: [],
      templateName: "",
      spinLoading: false, // 全局loading
    };

    this.detailColumns = [
      {
        key: 1,
        title: '输入域编码',
        dataIndex: 'internalCode',
        align: 'center',
        width: "220px"
      }, {
        key: 2,
        title: '输入域名称',
        dataIndex: 'fieldName',
        align: 'center',
        width: "200px"
      }, {
        key: 3,
        title: '输入域值',
        dataIndex: 'fieldData',
        align: 'center',
      }
    ];
    this.myRef1 = React.createRef();
  }

  componentDidMount() {
    this.setState({ basicHeight: document.getElementById("patient-medical-record-inquiry-basic").clientHeight }, () => {
      setTimeout(() => {
        this.myRef1 && this.myRef1.current && this.myRef1.current.focus();
      }, 300)
    });
    this.getAdmTypeSelect();
    this.getPatientColumns();
    this.initDefaultValue()
    this.handleQuery();
    this.loadBedData();
    this.getMedicalRecordTemplateSelectData();
    this.getTemplateList(); // 获取模板下拉数据
  }

  //获取就诊类型下拉框
  getAdmTypeSelect = () => {
    let data = {}
    $http.post('urlS', this, {
      code: '03050088',
      data: data,
      success: function (res) {
        if (res.errorCode == 0) {
          this.setState({
            admTypeSelectData: res.result.Data
          })
        }
      }
    })
  }

  //查询默认数据
  initDefaultValue = () => {
    let data = {
      params: [{
        defaultAppObj: {
          EMRBaseConfiger: ['BasicCaseInformationFormLocType'],
        }
      }]
    }
    $http.post('urlS', this, {
      code: "04110023",
      data: data,
      success: (res) => {
        if (+res.errorCode === 0) {
          const regex = /@/g;
          this.setState({
            // defaultValueObj: res.result,
            locType: res.result.BasicCaseInformationFormLocType ? (res.result.BasicCaseInformationFormLocType.replace(regex, '^')) : this.state.locType,
          }, () => {
            this.getLocSelectData();
          })
        }
      }
    })
  }

  // 获取病历模板下拉数据
  getMedicalRecordTemplateSelectData = () => {
    var params = {
      params: [{
        findTemp: "RELEASED"
      }]
    }
    $http.post('urlDeault', this, {
      code: "06050018",
      data: params,
      success: function (res) {
        if (+res.errorCode === 0) {
          let medicalRecordTemplateSelectData = res.result && res.result.data.length > 0 ? res.result.data : [];
          let medicalRecordTemplateID = medicalRecordTemplateSelectData && medicalRecordTemplateSelectData.length > 0 ? medicalRecordTemplateSelectData[0].id : undefined;
          this.setState({
            medicalRecordTemplateSelectData,
            medicalRecordTemplateID
          })
        }
      }
    });
  }

  //获取护理分组
  getLocSelectData = () => {
    let { userData, locType } = this.state;
    let data = {
      params: [{
        hospID: userData && userData.hospID ? userData.hospID : "",
        type: locType,
        docFlag: "1",
      }]
    }
    $http.post('urlS', this, {
      code: "04020008",
      data: data,
      success: function (res) {
        if (+res.errorCode === 0) {
          let locSelectData = res.result && res.result.Data && res.result.Data.length > 0 ? res.result.Data : [];
          let allLocID = [];
          let locDoctor = [];
          for (var i = 0; i < locSelectData.length; i++) {
            allLocID.push(locSelectData[i].id);
            if (locSelectData[i].code === "zhybek" || locSelectData[i].code === "zhybyk") {
              locDoctor = locDoctor.concat(locSelectData[i].locDoctor)
            }
          }
          let allLoc = {
            id: "all",
            descripts: "全部",
            descriptsSPCode: "qu",
            allLocID,
            locTypeCode: "I",
            locTypeDesc: "住院",
            locDoctor: Util.unique(locDoctor, "id")
          }
          console.log(allLoc)
          locSelectData.unshift(allLoc);
          this.setState({ locSelectData }, () => {
            this.handleLocIDChange(userData && userData.locID ? userData.locID : "")
          })
        } else {
          this.setState({ locSelectData: [] })
        }
      }
    })
  }

  loadBedData = () => {
    let { locID } = this.state;
    if (!locID) return;
    var params = {
      params: [{
        locID, // userData && userData.locID ? userData.locID : ""
      }]
    }
    $http.post('urlDeault', this, {
      code: "03060005",
      data: params,
      success: function (res) {
        if (+res.errorCode === 0) {
          this.setState({
            bedData: res.data
          })
        }
      }
    });
  }

  // 获取患者表头数据
  getPatientColumns = () => {
    let data = {
      params: [{
        compontName: "PreviewOfPatEMRPatList",
        type: "C",
      }]
    }
    $http.post('urlDeault', this, {
      code: "01040073",
      data: data,
      success: (res) => {
        if (+res.errorCode === 0) {
          var columns = res.result.C;
          var dynColumns = []
          for (var i = 0; i < columns.length; i++) {
            dynColumns.push({
              title: columns[i].title,
              dataIndex: columns[i].dataIndex,
              width: parseInt(columns[i].width),
              align: columns[i].align || 'center'
            })
          }
          this.setState({
            patientColumns: dynColumns,
            patientWidth: res.totalWidth
          })
        }
      }
    })
  }

  onColumnRef = (ref) => {
    this.columnRef = ref;
  }

  // 查询条件 --- 人员标识
  handlePatMessageChange = e => {
    this.setState({ patMessage: e.target.value })
  }

  // 查询条件 --- 住院号
  handleMedicalNoChange = e => {
    this.setState({ medicalNo: e.target.value })
  }

  // 查询条件 --- 床号
  handleBedIDChange = e => {
    this.setState({ bedID: e }, () => {
      this.handleQuery();
    })
  }

  // 查询条件 --- 主管医生
  handleAdmDocChange = e => {
    this.setState({ admDocID: e }, () => {
      this.handleQuery();
    })
  }

  // 查询条件 --- 科室名称
  handleLocIDChange = e => {
    let locTypeCode = ""
    let { locSelectData, locDocData, admDocID } = this.state
    let selLocDocData = []
    let selectLocAry = locSelectData.filter((item, index) => (item.id === e))
    if (selectLocAry.length > 0) {
      locTypeCode = selectLocAry[0].locTypeCode
      selLocDocData = selectLocAry[0].locDoctor
    }
    this.setState({
      locID: e, admStatusCode: undefined, admDocID: undefined,
      admStatusAble: ((locTypeCode !== "W") & (locTypeCode !== "I")) ? true : false,
      bedIDAble: ((locTypeCode !== "W") & (locTypeCode !== "I")) ? true : false,
      medicalNoAble: ((locTypeCode !== "W") & (locTypeCode !== "I")) ? true : false,
      locDocData: selLocDocData
    }, () => {
      this.handleQuery();
      this.loadBedData();
    })
  }

  // 查询
  handleQuery = () => {
    this.setState({ page: 1 }, () => {
      this.getTableData();
    })
  }

  getAllLocID = () => {
    let { locSelectData, locID } = this.state;
    let allLocID = [];
    for (var i = 0; i < locSelectData.length; i++) {
      if (locSelectData[i].id === locID) {
        allLocID = locSelectData[i].allLocID;
      }
    }
    return allLocID;
  }

  // 获取患者列表数据
  getTableData = () => {
    let { admTypeCode, userData, patMessage, bedID, medicalNo, locID, admStatusCode, page, pageSize, admissionDate, dateFrom, dateTo, admSTDate, admSPDate, isSubmit, admDocID } = this.state;
    let data = {
      params: [{
        admTypeCode: admTypeCode,
        locID: locID === "all" ? this.getAllLocID() : locID, // userData && userData.locID ? userData.locID : "",
        // userID: 164, // userData && userData.userID ? userData.userID : "",
        hospID: userData && userData.hospID ? userData.hospID : "",
        patMessage,
        bedID,
        medicalNo,
        admStatusCode,
        admissionDate: admissionDate ? Moment(admissionDate).format('YYYY-MM-DD') : undefined,
        dateFrom: admStatusCode === 'D' ? dateFrom : '',
        dateTo: admStatusCode === 'D' ? dateTo : '',
        admSTDate: admStatusCode !== 'D' ? admSTDate : '',
        admSPDate: admStatusCode !== 'D' ? admSPDate : '',
        // IsSubmit: isSubmit ? "Y" : "N",
        purpose: "PreviewPatRecord",
        // admDocID
      }],
      pagination: [{
        pageSize,
        currentPage: page
      }]
    }
    $http.post('urlDeault', this, {
      code: "06080002",
      data: data,
      success: function (res) {
        if (+res.errorCode === 0) {
          this.setState({
            tableData: res.result.data,
            total: res.result.totalCount,
            rowId: "",
            rowRow: {},
            selectedRowKeys: [],
            selectedRows: [],
            detailTableData: [],
            detailTotal: 0,
            detailSelectedRowKeys: [],
            detailSelectedRows: []
          })
        } else {
          this.setState({
            tableData: [],
            total: 0,
            rowId: "",
            rowRow: {},
            selectedRowKeys: [],
            selectedRows: [],
            detailTableData: [],
            detailTotal: 0,
            detailSelectedRowKeys: [],
            detailSelectedRows: []
          })
        }
      }
    });
  }

  // 患者列表 -- 条数改变的回调
  handleLeftShowSizeChange = (current, size) => {
    this.setState({ page: 1, pageSize: size }, () => {
      this.getTableData();
    });
  }

  // 患者列表 -- 页码改变的回调
  handleLeftChange = (page, pageSize) => {
    this.setState({ page, pageSize }, () => {
      this.getTableData();
    });
  }

  // 操作行 --- 患者列表
  onClickRowPublic = (record) => {
    return {
      // 单击行选中
      onClick: () => {
        if (this.state.rowId === '') {
          // 保存行数据以及ID
          this.setState({ rowId: record.admID, rowRow: record }, () => {
            if (this.state.medicalRecordTemplateID) {
              this.getTreeData(); // 获取该模板的保存记录
            }
          })
        } else {
          if (this.state.rowId !== record.admID) {
            this.setState({ rowId: record.admID, rowRow: record }, () => {
              if (this.state.medicalRecordTemplateID) {
                this.getTreeData(); // 获取该模板的保存记录
              }
            })
          }
        }
      }
    }
  }

  setRowClassNamePublic = (record) => {
    return record.admID === this.state.rowId ? 'clickRowStyle' : "";
  }

  handleAdmTypeCodeChange = e => {
    this.setState({
      admTypeCode: e,
      admStatusAble: (e !== "I") ? true : false, bedIDAble: (e !== "I") ? true : false, medicalNoAble: (e !== "I") ? true : false
    }, () => {
      this.handleQuery();
    })
  }

  handleAdmStatusCodeChange = e => {
    this.setState({ admStatusCode: e }, () => {
      this.handleQuery();
    })
  }

  handleAdmissionDateChange = e => {
    this.setState({ admissionDate: e })
  }

  startChange = (e) => {
    this.setState({
      dateFrom: e ? Moment(e).format(dayFormat) : ''
    })
  }

  handleAdmSTDStartChange = (e) => {
    this.setState({
      admSTDate: e ? Moment(e).format(dayFormat) : ''
    })
  }

  endChange = (e) => {
    this.setState({
      dateTo: e ? Moment(e).format(dayFormat) : ''
    })
    // 就诊类型：
    // <Select value={admTypeCode} onChange={this.handleAdmTypeCodeChange} showSearch optionFilterProp="seatchprop" allowClear placeholder="请选择" style={{ width: '150px', margin: '22px 10px 0 0' }}>
    //   {admTypeOption}
    // </Select>
  }

  handleAdmSTDEndChange = (e) => {
    this.setState({
      admSPDate: e ? Moment(e).format(dayFormat) : ''
    })
  }

  // 回退
  handleBackOff = () => {
    let { rowId, userData } = this.state;
    if (!rowId) return;
    let data = {
      params: [{
        statusCode: "R",
        type: "ALL",
        admID: rowId,
      }]
    }
    $http.post('urlS', this, {
      code: "06050022",
      data: data,
      success: function (res) {
        if (+res.errorCode === 0) {
          message.success(res.errorMessage, userData && userData.messageTime ? userData.messageTime : 3);
        }
      }
    })
  }

  // 是否已提交
  handleIsSubmitChange = e => {
    this.setState({ isSubmit: e }, () => {
      this.handleQuery();
    })
  }

  // 获取模板下拉数据
  getTemplateList = () => {
    let data = {
      params: [{
        typePower: "textTemplate",
        isReleaseVer: "Y", // 查询有发布版本的模板
      }]
    }
    $http.post('urlS', this, {
      code: "06020003",
      data: data,
      success: function (res) {
        if (+res.errorCode === 0) {
          this.setState({ templateList: res.result });
        }
      }
    })
  }

  // 选择模板
  handleMedicalRecordTemplateIDChange = e => {
    this.setState({ medicalRecordTemplateID: e }, () => {
      this.getTreeData(); // 获取该模板的保存记录
    });
  }

  onExpand = (expandedKeys) => {
    // console.log("触发了onExpand", expandedKeys)
    this.setState({
      expandedKeys,
      autoExpandParent: false,
    });
  }

  // 病历模板树选中操作
  onSelect = (keys, event) => {
    let { spinLoading } = this.state;
    let selectData = event.node.props.dataRef;
    if ((selectData && selectData.treeType !== "TEMPLATE") || spinLoading) { // 树类型不为TEMPLATE时不给予选中及其他操作
      return;
    }
    if (!(keys && keys.length > 0)) {
      return;
    }
    this.setState({ selectedKeys: keys, spinLoading: true, loadingTitle: "病历加载中……" }, () => {
      if (this.state.selectedKeys && this.state.selectedKeys.length > 0) {
        // this.setState({ treeSelectData:  }, () => {
        this.loadingMedicalRecords(selectData);
        // })
      } else {
        this.setState({ treeSelectData: {} })
      }
    })
  }

  dblclickTreeNodes = (status, record) => {
    let { spinLoading } = this.state;
    let selectData = record.props.dataRef;
    let parentID = selectData.parentID;
    let ID = selectData.ID;
    if ((selectData && selectData.treeType !== "TEMPLATE") || spinLoading) { // 树类型不为TEMPLATE时不给予选中及其他操作
      return;
    }
    if (!parentID) {
      return;
    } else {
      let key = [];
      key.push(ID);
      // console.log("key", key)
      this.setState({ selectedKeys: key, spinLoading: true, loadingTitle: "病历加载中……" }, () => {
        this.loadingMedicalRecords(selectData);
      })
    }
  }

  // 加载病历
  loadingMedicalRecords = (record) => {
    let { rowRow } = this.state;
    let data = {
      params: [{
        patRecDataID: record && record.BSEMRRDParRef ? record.BSEMRRDParRef : (record && record.patEMRRecordID ? record.patEMRRecordID : (record.ID ? record.ID : "")),
        admID: this.state.rowId,
        groupTemplateID: record && record.templateID ? record.templateID : "", // 分组模板ID
        power: this.props.medicalType == 'Z' ? 'OutHospRecord' : ""
      }]
    }
    $http.post('urlS', this, {
      code: "06050016",
      data: data,
      success: function (res) {
        if (+res.errorCode === 0) {
          let templatePath = res.result && res.result.templatePath ? res.result.templatePath : '';
          let authority = res.result && res.result.authority ? res.result.authority : {};
          let isOperable = authority && (authority.addOrNot === "Y" || authority.updateOrNot === "Y") ? "N" : "Y"; // 是否可操作
          let progressID = record && record.progressID ? record.progressID : ""; // 病程记录ID
          this.setState({ templatePath, spinLoading: false }, () => {
            this.state.templatePath ? (this.caseTemplateChild && this.caseTemplateChild.setElementTextByID && this.caseTemplateChild.setElementTextByID(
              this.state.templatePath,
              res.result.dataSource,
              isOperable,
              "boolFalse",
              rowRow && rowRow.patSexDesc ? rowRow.patSexDesc : "",
              { ...record, releaseVersion: record?.releaseVersion || '' },
              record && record.templateID ? record.templateID : "",
              progressID
            )) : ""
          })
        } else {
          this.setState({ patientHistoryData: [], spinLoading: false })
        }
      },
      error: function () {
        this.setState({ patientHistoryData: [], spinLoading: false })
      }
    })
  }

  getParentKey = (key, tree) => {
    let parentKey;
    for (let i = 0; i < tree.length; i++) {
      const node = tree[i];
      if (node.children) {
        if (node.children.some(item => item.key === key)) {
          parentKey = node.key;
        } else if (this.getParentKey(key, node.children)) {
          parentKey = this.getParentKey(key, node.children);
        }
      }
    }
    return parentKey;
  };

  //以下是Tree展开搜索
  dataList = [];
  generateList = (data) => {
    for (let i = 0; i < data.length; i++) {
      const node = data[i];
      const key = node.key;
      this.dataList.push({ key, title: node.title });
      if (node.children) {
        this.generateList(node.children);
      }
    }

    // 默认进来tree全部加载
    const expandedKeys = this.dataList.map((item) => {
      return this.getParentKey(item.key, this.state.treeData);
    }).filter((item, i, self) => item && self.indexOf(item) === i);
    this.setState({
      expandedKeys,
    });
  };

  // 处理tree数据
  filterTreeData = (treeData, type, oldItem) => {
    let data = treeData && treeData.map(item => {
      // 当为首程并且首程下存在病程时则首程的progressID就为病程ID;
      let progressID = item && item.subCatalog && item.subCatalog.length > 0 && item.subCatalog[0].treeType && item.subCatalog[0].treeType === "PROGRESS" ? "first" : "";
      return {
        ...item,
        title: item.descripts,
        key: item.ID,
        ID: item && item.treeType && item.treeType === "PROGRESS" ? (oldItem && oldItem.ID ? oldItem.ID : "") : item.ID,
        progressID: item && item.treeType && item.treeType === "PROGRESS" ? item.ID : progressID,
        treeType: item && item.treeType ? item.treeType : (item && item.subCatalog ? "CATALOG" : "TEMPLATE"),
        // ...oldItem,
        templateID: item.templateID ? item.templateID : (oldItem && oldItem.templateID ? oldItem.templateID : ""),
        children: this.filterTreeData(item.subCatalog, type, item)
      }
    });
    return data;
  }

  // 3.6.1.根据患者获取病历模板分组目录树
  getTreeData = (type) => {
    let { rowId, medicalRecordTemplateID } = this.state;
    let data = {
      params: [{
        admID: [rowId],
        templateID: [medicalRecordTemplateID]
      }]
    }
    $http.post('urlS', this, {
      code: "06050023",
      data: data,
      success: function (res) {
        if (+res.errorCode === 0) {
          let arr = this.filterTreeData(res.result.data, type);
          this.setState({ treeData: arr }, () => {
            this.generateList(this.state.treeData, "treeData")
          })
        } else {
          this.setState({ treeData: [] })
        }
      }
    })
  }

  // 渲染树节点
  renderTreeNodes = data => data && data.map((item) => {
    let inputValue = this.state.templateName;
    const index = item.title && item.title.indexOf(inputValue);
    const beforeStr = item.title && item.title.substr(0, index);
    const afterStr = item.title && item.title.substr(index + inputValue.length);
    const title = index > -1 ? (
      <span>
        {beforeStr}
        <span style={{ color: '#FF7F00' }}>{inputValue}</span>
        {afterStr}
      </span>
    ) : <span>{item.title}</span>;
    // progressID存在并且不等于first则为病程 为first则为首程（病程主节点）
    let type = item.treeType === 'CATALOG' ? 'folder-open' : (item.treeType === 'TEMPLATE' ? 'folder' : 'file');
    if (item.children) {
      return (
        <TreeNode icon={<Icon type={type} />} title={title} key={item.key} dataRef={item}>
          {this.renderTreeNodes(item.children)}
        </TreeNode>
      );
    }
    return <TreeNode icon={<Icon type={type} />} title={title} key={item.key} dataRef={item} />;
  })

  handleCaseTemplateRef = ref => {
    this.caseTemplateChild = ref;
  }

  handleSave = () => {

  }

  render() {
    let { patientColumns, tableData, total, page, basicHeight, loading, patMessage, medicalNo, bedID, locID, patientWidth, bedData, locSelectData,
      medicalRecordTemplateSelectData, rowId, admStatusCode, admStatusSelectData, isSubmit, rowRow, admTypeSelectData, medicalRecordTemplateID, templateList,
      admStatusAble, bedIDAble, medicalNoAble, docNameAble, locDocData, admDocID, autoExpandParent, expandedKeys, selectedKeys, treeData, loadingTitle,
      spinLoading
    } = this.state;

    // 床号
    var bedDataOption = []
    bedData && bedData.map((item, index) => {
      bedDataOption.push(<Option key={index} value={item.bedID} title={item.bedNo} seatchprop={item.bedNo}>
        {item.bedNo}
      </Option>)
    })

    // 
    var locOption = []
    locSelectData && locSelectData.map((item, index) => {
      locOption.push(<Option key={index} code={item.descriptsSPCode} value={item.id} seatchprop={item.descripts + '^' + item.descriptsSPCode} title={item.descripts}>{item.descripts}</Option>)
    })

    //科室医生
    var locDocDataOption = []
    locDocData && locDocData.map((item, index) => {
      locDocDataOption.push(<Option key={index} code={item.descriptsSPCode} value={item.id} seatchprop={item.descripts + '^' + item.descriptsSPCode} title={item.descripts}>{item.descripts}</Option>)
    })

    // 病历模板
    var medicalRecordTemplateOption = [];
    medicalRecordTemplateSelectData && medicalRecordTemplateSelectData.map((item, index) => {
      medicalRecordTemplateOption.push(<Option key={index} code={item.descriptsSPCode} value={item.id} seatchprop={item.descripts + '^' + item.descriptsSPCode} title={item.descripts}>{item.descripts}</Option>)
    })

    // 就诊类型
    let admTypeOption = [];
    admTypeSelectData && admTypeSelectData.map((item, index) => {
      admTypeOption.push(<Option key={index} code={item.admCode} value={item.admCode} seatchprop={item.admDesc + '^' + item.descriptsSPCode} title={item.admDesc}>{item.admDesc}</Option>)
    })

    // 患者类型
    let admStatusOption = [];
    admStatusSelectData && admStatusSelectData.map((item, index) => {
      admStatusOption.push(<Option key={index} code={item.descriptsSPCode} value={item.id} seatchprop={item.descripts + '^' + item.descriptsSPCode} title={item.descripts}>{item.descripts}</Option>)
    })

    // 模板下拉数据
    let templateOption = [];
    templateList && templateList.map((item, index) => {
      templateOption.push(<Option key={index} code={item.descriptsSPCode} value={item.ID} seatchprop={item.descripts + '^' + item.descriptsSPCode} title={item.descripts}>{item.descripts}</Option>)
    })

    let param = {
      isInsert: "hidden",
      formView: "Normal",
      headerFooterEditable: "noEditable",
      isFont: true,
      isDelete: true, // 删除按钮操作状态
      isBasicOperation: true
    }

    return (
      <Spin tip={loadingTitle} spinning={spinLoading} delay={300} style={{ height: "100%" }}>
        <div className="patient-medical-record-inquiry">
          <Row id="patient-medical-record-inquiry-basic" style={{ padding: '0 12px' }}>
            <Col span={24} className="input-padding-right">
              <Row style={{ marginBottom: '20px' }}>
                科室名称：
                <Select value={locID} onChange={this.handleLocIDChange} showSearch optionFilterProp="seatchprop" allowClear placeholder="请选择" style={{ width: '150px', margin: '22px 10px 0 0' }}>
                  {locOption}
                </Select>
                患者类型：
                <Select value={admStatusCode} onChange={this.handleAdmStatusCodeChange}
                  disabled={admStatusAble}
                  showSearch optionFilterProp="seatchprop" allowClear placeholder="请选择" style={{ width: '150px', margin: '22px 10px 0 0' }}>
                  {admStatusOption}
                </Select>
                床号：
                <Select value={bedID} onChange={this.handleBedIDChange}
                  disabled={bedIDAble}
                  showSearch optionFilterProp="seatchprop" allowClear placeholder="请选择" style={{ width: '100px', margin: '22px 10px 0 0' }}>
                  {bedDataOption}
                </Select>
                住院号：
                <Input value={medicalNo} allowClear
                  disabled={medicalNoAble}
                  onChange={this.handleMedicalNoChange}
                  placeholder='请输入'
                  onPressEnter={this.handleQuery}
                  style={{ width: '150px', margin: '22px 10px 0 0' }}
                />
                人员标识：
                <Input value={patMessage} allowClear
                  onChange={this.handlePatMessageChange}
                  ref={this.myRef1}
                  onPressEnter={this.handleQuery}
                  placeholder='请输入病人信息'
                  style={{ width: '150px', margin: '22px 10px 0 0' }}
                />
                {/* 主管医生：
              <Select value={admDocID} onChange={this.handleAdmDocChange}
                  disabled={docNameAble}
                  showSearch optionFilterProp="seatchprop" allowClear placeholder="请选择" style={{ width: '150px', margin: '22px 10px 0 0' }}>
                  {locDocDataOption}
                </Select> */}
                <div style={{ display: "inline-block" }}>
                  {/* 就诊(入院)日期：<DatePicker value={admissionDate} style={{ width: '150px', margin: '22px 0 0 0' }}
                placeholder='请选择入院日期' onChange={this.handleAdmissionDateChange} /> */}
                  {admStatusCode !== 'D' ? (<div style={{ display: 'inline-block', margin: '8px 10px 0 0' }}>
                    <RangeDatePicker label={'就诊(入院)日期：'} format='YYYY-MM-DD' width='270px'
                      startChange={this.handleAdmSTDStartChange} endChange={this.handleAdmSTDEndChange} />
                  </div>) : ""}
                  {admStatusCode === 'D' ? (<div style={{ display: 'inline-block', margin: '8px 10px 0 0' }}>
                    <RangeDatePicker label={'出院日期：'} format='YYYY-MM-DD' width='270px'
                      startChange={this.startChange} endChange={this.endChange} />
                  </div>) : ""}
                  {/* 已提交：
                <Switch checkedChildren="是" unCheckedChildren="否" checked={isSubmit} onChange={this.handleIsSubmitChange} /> */}
                  <Button type="primary" style={{ marginTop: '8px', marginLeft: "10px" }} onClick={this.handleQuery}>查询</Button>
                </div>
              </Row>
            </Col>
          </Row>
          <div style={{ height: '6px', background: 'rgba(240, 242, 245, 1)', width: '100%' }}></div>
          <Row>
            <Col span={7}>
              <div style={{ paddingRight: '6px', position: 'relative' }}>
                <Card
                  size="small"
                  title={<div className="card-title-left-img" style={{ height: "32px" }}><img src={iconListvisits} alt="" />患者列表</div>}
                >
                  <div>
                    <Table
                      columns={patientColumns && patientColumns.length > 0 ? patientColumns : []}
                      dataSource={tableData}
                      style={{ height: store.getState().tableHeight.y + 125 - basicHeight + 'px', }}
                      scroll={{ x: patientWidth, y: store.getState().tableHeight.y + 79 - basicHeight }}
                      // rowSelection={rowSelection}
                      onRow={this.onClickRowPublic}
                      rowClassName={this.setRowClassNamePublic}
                      onHeaderRow={() => {
                        return {
                          onDoubleClick: () => {
                            this.columnRef.onOpenModel();
                          },
                        };
                      }}
                      bordered
                      rowKey={(data) => {
                        return data.admID
                      }}
                      pagination={false}
                      className="table-body-height" />
                    <CommonPagination current={page} total={total} search="search" pageSize="20"
                      onShowSizeChange={this.handleLeftShowSizeChange} complete={true} dataSource={tableData} size='small'
                      loading={loading} onChange={this.handleLeftChange} />
                  </div>
                </Card>
                <div style={{ width: '6px', background: 'rgba(240, 242, 245, 1)', position: 'absolute', top: 0, right: 0, height: '100%' }}></div>
              </div>
            </Col>
            <Col span={17} style={{ height: store.getState().tableHeight.y + 235 - basicHeight + "px" }}>
              <div style={{ width: "260px", height: "100%", display: 'inline-block', overflow: 'hidden', paddingRight: '6px', position: 'relative' }}>
                <div style={{ textAlign: "center", height: '34px', lineHeight: '34px', fontWeight: 900, fontSize: "14px", background: "#fafafa", borderBottom: "1px solid #e8e8e8" }}>
                  患者病历
                </div>
                <div style={{ height: "calc(100% - 34px)", overflow: 'auto' }}>
                  <div style={{ width: '100%', padding: "8px 8px 0" }}>
                    <Select style={{ width: "100%" }} value={medicalRecordTemplateID} onChange={this.handleMedicalRecordTemplateIDChange} placeholder="请选择病历模板" showSearch optionFilterProp="seatchprop">
                      {templateOption}
                    </Select>
                  </div>
                  <Tree showIcon
                    style={{ height: "calc(100% - 40px)", overflow: "auto", }}
                    autoExpandParent={autoExpandParent}
                    onExpand={this.onExpand}
                    expandedKeys={expandedKeys}
                    onSelect={this.onSelect}
                    selectedKeys={selectedKeys}
                    onDoubleClick={this.dblclickTreeNodes}>
                    {this.renderTreeNodes(treeData)}
                  </Tree>
                </div>
                <div style={{ position: 'absolute', right: '0', top: '0', width: '6px', background: 'rgba(240, 242, 245, 1)', height: '100%' }}></div>
              </div>
              <div style={{ width: "calc(100% - 260px)", height: "100%", position: 'relative', overflow: "hidden", display: "inline-block" }}>
                <ElectronicCaseTemplate
                  param={param}
                  onRef={this.handleCaseTemplateRef}
                  handleSave={this.handleSave}
                  editorID={"PatientRecordsAll"}
                />
              </div>
            </Col>
          </Row>
          <ColumnAuthoritysModel
            clientWidth='800px'
            compontName="PreviewOfPatEMRPatList"
            configType="C"
            onRef={this.onColumnRef}
            reloadData={this.getPatientColumns}
          />
        </div>
      </Spin>
    );
  }
}

export default PatientRecordsAll;